var advList=[];  //广告数据
var serviceUrl = $api.getStorage('serviceUrl'); //服务器地址

apiready = function(){
// getindexData();
};


//获取首页信息
function getindexData(){
   
   do_ajax('/app/getcommAdvert','get',{},function(ret,err){
       
       if(ret){
           advList =ret.ad1;
	       openScrollPicture();
	       
	       api.hideProgress();
       }else{
            api.alert({
	            msg:('错误码：'+err.code+'；错误信息：'+err.msg+'网络状态码：'+err.statusCode)
	        });
	        api.hideProgress();
       
       }
   
   
   });
   


};


//设置滑动图片
function openScrollPicture(){

    var paths = [];

   
    for(var i=0;i<advList.length;i++){
	     paths.push(serviceUrl+advList[i].img);
	}

	var obj = api.require('UIScrollPicture');
	
//	var $right = $api.byId('rightw');
//	var rightwidth=$api.offset($right).w;   //右边宽度
//	var picturewidth=api.winWidth-rightwidth;  
	
	
	obj.open({
	    rect: {
	        x: 0, y: 0, w:api.winWidth, h:150
	    },
	    data: {
	        paths: paths,
	    },
	    styles: {
	        indicator: {
	            align: 'right',
	            color: '#666',
	            activeColor: '#ffaa43'
	        }
	    },
	    placeholderImg: 'widget://res/slide1.jpg',
	    contentMode: 'scaleToFill',
	    interval: 3,
	    loop: true,
	    fixedOn: 'lifeservice',
	    fixed: false
	}, function(ret, err){
	     if(ret.status){
	        if(ret.eventType == 'click'){
	            //点击图片的操作
	            //alert(ret.index);
	        }
	     }
	});

};


function openProductList(param){
	api.openWin({
        name: 'productlist',
        url: '../shop/productlist.html',
        pageParam: param,
        opaque: true,
        vScrollBarEnabled:false
    });
}

